from sys_value import *
from file_manager import save_data
from decorator import decorator


@decorator
def login():
    username = input('请输入用户名:').strip()
    password = input('请输入密码:').strip()
    user_info = get_user_info()
    if user_info.get(username):
        if user_info.get(username) == password:
            print('登录成功！')
            set_current_user(username)
            return True

    print('用户名或密码错误！')
    return False


@decorator
def register():
    username = input('请输入注册的用户名:').strip()
    user_dict = get_user_info()
    if user_dict.get(username):
        print('当前用户已存在！请重新输入')
        return register()
    password = input('请输入用户密码:').strip()
    user_dict[username] = password
    set_user_info(user_dict)
    save_data()
    print('注册成功！')
    return
